package com.yylending.las.authority.password;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yylending.las.common.RSAEntity;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
 * Created by laixj on 2017/5/26.
 * Copyright ©2016 www.yylending.com. All Rights Reserved.
 */
public class ResetPasswordModel extends Model {
	private static final String TAG = "LoginModel";

	public final static int METHOD_RESET_PASSWORD = 1;

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		switch (functionalCode) {
			case METHOD_RESET_PASSWORD:
				return service.resetPassword("", new RSAEntity(params));
		}
		return null;
	}

	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		BaseResultEntity result = cast(obj);
		switch (result.requestCode) {
			case METHOD_RESET_PASSWORD:
				ResetPwdResult resetPwdResult = cast(obj);
				EventAgent.post(resetPwdResult);
				break;
		}
	}

	private interface Service {
		/**
		 * 重置密码
		 */
		@POST("server/cuser/resetPassword")
		Observable<ResetPwdResult> resetPassword(@Header("token") String token, @Body RSAEntity account);
	}

	static class ResetPwdResult extends BaseResultEntity<String> {
	}

	public static class ResetPassword {
		public String mobile;
		public String password;
		public String verify;

		public ResetPassword(String mobile, String password, String verify) {
			this.mobile = mobile;
			this.password = password;
			this.verify = verify;
		}
	}

}